/*
 * @Author: your name
 * @Date: 2021-06-04 22:53:28
 * @LastEditTime: 2021-06-04 23:38:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \HW5\src\q2.cpp
 */
#include "../inc/q2.hpp"

using namespace std;

static bool bInputIsRight(char *input)
{
    for (int i = 0; i < 10; i++)
    {   
        if(input[i]==0)
            return true;
        if (!(input[i]>='0'&&input[i]<='9'))
            return false;
    }
    return true;
}

void testQ2()
{
    
    int i = 0;
    vector<int> num;
    int temp;
    char inputStr[10];
    while (i < 10)
    {
        cout << "Please a Number less than 10^10" << endl;
        try
        {
            cin >> inputStr;
            if (!bInputIsRight(inputStr))
                throw "input invalid!";
        }
        catch (const char *msg)
        {
            std::cerr << msg << '\n';
            temp = 0;
            cin.clear();
            while (cin.get() != '\n')
            {
                continue; // 清空缓冲区
            }
            continue;
        }
        temp=atoi(inputStr);  
        num.push_back(temp);
        ++i;
    }
    int max = * (num.begin());
    int min =* (num.begin());
    for (auto ite = num.begin(); ite != num.end(); ++ite)
    {
        if (max < *ite)
        {
            max = *ite;
        }
        if(min>*ite)
        {
            min=*ite;
        }
    }
    cout <<"MAX Number is :"<<max <<"and Min Number is "<<min;
}